package net.aiion.weave.spi.startup;

import java.util.ServiceLoader;

public abstract class Startup
{
    private static Startup startupFactory;

    public Startup() {
    }

    public abstract GlobalContextStartup usingGlobalContext();

    public static Startup getInstance() {
        if (startupFactory == null) {
            for (Startup startup : StartupFactoryServiceLoader.SERVICE_LOADER) {
                startupFactory = startup;
                break;
            }
        }

        return startupFactory;
    }

    private static final class StartupFactoryServiceLoader
    {
        private static final ServiceLoader<Startup> SERVICE_LOADER = ServiceLoader.load(Startup.class);

        private StartupFactoryServiceLoader() {
        }
    }
}
